{extend name="public/layout" /}
{block name="body"}
    <form class="layui-form" > <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
        <div class="layui-card pd-bt-15">
            <div class="layui-row">
                <div class="layui-col-md8">
                    <div class="layui-form-item">
                        <label class="layui-form-label">权限名字</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" value="{$vo.name|default=''}" lay-verify="required"  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md4">
                    <div class="layui-form-mid layui-word-aux">请输入权限名字</div>
                </div>
            </div>

            <div class="layui-row">
                <div class="layui-col-md2">
                    <div class="layui-form-item">
                        <label class="layui-form-label">Module</label>
                        <div class="layui-input-block">
                            <input type="text" name="module" value="{$vo.module|default='admin'}" lay-verify="required"  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md2">
                    <div class="layui-form-item">
                        <label class="layui-form-label">Controller</label>
                        <div class="layui-input-block">
                            <input type="text" name="controller" value="{$vo.controller|default=''}" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md2">
                    <div class="layui-form-item">
                        <label class="layui-form-label">Action</label>
                        <div class="layui-input-block">
                            <input type="text" name="action" value="{$vo.action|default=''}" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md2">
                    <div class="layui-form-item">
                        <label class="layui-form-label">排序</label>
                        <div class="layui-input-block">
                            <input type="text" name="sort" value="{$vo.sort|default=999}" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-row">
                <div class="layui-col-md8">
                    <div class="layui-form-item">
                        <label class="layui-form-label">上级权限</label>
                        <div class="layui-input-block">
                            <select name="pid"  lay-search>
                                <option value="0">无上级</option>
                                {foreach name='auth_list' item='item'}
                                    <option {if condition="$vo.pid eq $item.id"}selected{/if} value="{$item.id}">{$item.name}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md4">
                    <div class="layui-form-mid layui-word-aux">该权限的上级</div>
                </div>
            </div>

            <div class="layui-row">
                <div class="layui-col-md8">
                    <div class="layui-form-item">
                        <label class="layui-form-label">上级导航</label>
                        <div class="layui-input-block">
                            <select name="nav_pid" lay-search>
                                <option value="0">无上级</option>
                                {foreach name='auth_list' item='item'}
                                    <option {if condition="$vo.nav_pid eq $item.id"}selected{/if} value="{$item.id}">{$item.name}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md4">
                    <div class="layui-form-mid layui-word-aux">用于生成页面内导航</div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">是否菜单</label>
                <div class="layui-input-block">
                    <input name="is_menu" type="checkbox" lay-skin="switch" {if condition="$vo.is_menu eq 1"}checked{/if}>
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">当前状态</label>
                <div class="layui-input-block">
                    <input name="status" type="checkbox" lay-skin="switch" {if condition="$vo.status eq 1"}checked{/if}>
                </div>
            </div>

            <input type="hidden" name="id" value="{$vo.id}"/>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
                </div>
            </div>
        </div>
    </form>
{/block}
{block name="script"}
    <script>
        layui.use('form',function(){
            var form = layui.form,
                $ = layui.$;
            form.on('submit(*)', function(data){
                var url =  "{$act}";
                if(data.field.is_menu == 'on'){
                    data.field.is_menu = 1;
                }else{
                    data.field.is_menu = 0;
                }
                if(data.field.status == 'on'){
                    data.field.status = 1;
                }else{
                    data.field.status = 0;
                }
                $.post(url,data.field,function(data){
                    if(data.code == 10000)
                    {
                        layer.msg(data.msg,{icon:1,time:1500},function(){
                            window.location.href = "{:url('index')}";
                        })
                    }else{
                        layer.msg(data.msg,{icon:2,time:1500})
                    }

                });
                return false;
            });

        });
    </script>
{/block}